package io.renren.modules.answer.controller;

import io.renren.common.utils.PageInput;
import io.renren.common.utils.PageUtils;
import io.renren.modules.answer.dto.input.QuestionAnswerInput;
import io.renren.modules.answer.service.ExamService;
import io.renren.modules.sys.entity.SysUserEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Author liangbaigao
 * @Date 2022/10/7 16:26
 */
@Api(tags = "在线考试")
@RestController
@RequestMapping("/exam")
public class ExamController {

    @Resource
    private ExamService examService;

    /**
     * 提交问卷
     */
    @ApiOperation("问卷提交")
    @PostMapping("/submitQuestion")
    public void submitQuestion(@RequestBody @Valid QuestionAnswerInput questionAnswerInput){
        examService.submitQuestion((SysUserEntity) SecurityUtils.getSubject().getPrincipal(), questionAnswerInput);
    }

    /**
     * 查看试卷 已发布的
     */
    @ApiOperation("查看试卷")
    @PostMapping("/showExam")
    public PageUtils showExam(@RequestBody @Valid PageInput input){
        return examService.showExam(input);
    }

    /**
     * 查看成绩 总分 管理员看全部 非管理员看自己的
     */
    @ApiOperation("查看成绩")
    @PostMapping("/showScore")
    public PageUtils showScore(@RequestBody @Valid PageInput input){
        return examService.showScore(input);
    }

}
